package com.bdmc.web.controller.report;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.bdmc.common.annotation.RepeatSubmit;
import com.bdmc.common.annotation.Log;
import com.bdmc.common.core.controller.BaseController;
import com.bdmc.common.core.domain.PageQuery;
import com.bdmc.common.core.domain.AjaxResult;
import com.bdmc.common.core.validate.AddGroup;
import com.bdmc.common.core.validate.EditGroup;
import com.bdmc.common.core.validate.QueryGroup;
import com.bdmc.common.enums.BusinessType;
import com.bdmc.common.utils.poi.ExcelUtil;
import com.bdmc.report.domain.vo.ReportCarAccVo;
import com.bdmc.report.domain.bo.ReportCarAccBo;
import com.bdmc.report.service.IReportCarAccService;
import com.bdmc.common.core.page.TableDataInfo;


/**
 * 车辆点火熄火控制器
 *
 * @author bdmc
 * @date 2022-08-08
 */
@Validated
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/report/carAcc")
public class ReportCarAccController extends BaseController {

    private final IReportCarAccService iReportCarAccService;

    /**
     * 查询车辆点火熄火列表
     */
    @SaCheckPermission("report:carAcc:list")
    @GetMapping("/list")
    public TableDataInfo<ReportCarAccVo> list(@Validated(QueryGroup.class) ReportCarAccBo bo, PageQuery pageQuery) {
        return iReportCarAccService.mySelectPage(bo, pageQuery);
    }

    /**
     * 导出车辆点火熄火列表
     */
    @SaCheckPermission("report:carAcc:export")
    @Log(title = "车辆点火熄火", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated ReportCarAccBo bo, HttpServletResponse response) {
        List<ReportCarAccVo> list = iReportCarAccService.queryList(bo);
        ExcelUtil.exportExcel(list, "车辆点火、熄火统计", ReportCarAccVo.class, response);
    }

    /**
     * 获取车辆点火熄火详细信息
     */
    @SaCheckPermission("report:carAcc:query")
    @GetMapping("/{accId}")
    public AjaxResult<ReportCarAccVo> getInfo(@PathVariable("accId") Long accId) {
        return AjaxResult.success(iReportCarAccService.queryById(accId));
    }

    /**
     * 新增车辆点火熄火
     */
    @SaCheckPermission("report:carAcc:add")
    @Log(title = "车辆点火熄火", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody ReportCarAccBo bo) {
        return toAjax(iReportCarAccService.insertByBo(bo));
    }

    /**
     * 修改车辆点火熄火
     */
    @SaCheckPermission("report:carAcc:edit")
    @Log(title = "车辆点火熄火", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody ReportCarAccBo bo) {
        return toAjax(iReportCarAccService.updateByBo(bo));
    }

    /**
     * 删除车辆点火熄火
     */
    @SaCheckPermission("report:carAcc:remove")
    @Log(title = "车辆点火熄火" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{accIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] accIds) {
        return toAjax(iReportCarAccService.deleteWithValidByIds(Arrays.asList(accIds), true));
    }
}
